﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ETL.Common.Logging;
using ETL.DataAccess;

namespace ETL.Business.Handlers.ProjectTaskHandler
{
    public class DeleteProjectTask
    {
        private readonly ProjectTaskRepository _projectTaskRepository;
        private readonly ProjectActualResourceUsageRepository _projectActualResourceRepository;
        private readonly ProjectScheduledResourceUsageRepository _projectScheduledResourceUsageRepository;

        public DeleteProjectTask(ProjectTaskRepository projectTaskRepository)
        {
            _projectTaskRepository = projectTaskRepository;
        }
        public DeleteProjectTask()
        {
            _projectTaskRepository = new ProjectTaskRepository();
            _projectActualResourceRepository = new ProjectActualResourceUsageRepository();
            _projectScheduledResourceUsageRepository = new ProjectScheduledResourceUsageRepository();
        }

        public virtual int Execute(string taskId)
        {
            int result = -1;
            try
            {
                _projectScheduledResourceUsageRepository.DeleteScheduledResourceUsages(taskId);
                result = _projectTaskRepository.DeleteProjectTask(taskId);
                return result;
            }
            catch (Exception ex)
            {
                LogService.Service.Error(ex);
                return -1;

            }

        }
    }
}
